/*
 * @Author: 火红色祥云 809880192@qq.com
 * @Date: 2022-06-14 21:52:13
 * @LastEditors: 火红色祥云 809880192@qq.com
 * @LastEditTime: 2022-09-27 21:49:51
 * @FilePath: /imx6ull-app/02_led/chardevledApp.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/types.h"
#include "fcntl.h"

#define LED_ON  1
#define LED_OFF 0


int main(int argc, char *argv[])
{

    int fd,ret_val;
    unsigned char *filename;
    unsigned char data[1];
    if (argc != 3)
    {
        printf("Usage: ERROR\r\n");
        return -1;
    }
    
    filename = argv[1];

    fd = open(filename,O_RDWR);
    if (fd < 0)
    {
        printf("file open failed\r\n");
        return -1;
    }

    data[0] = atoi(argv[2]);

    ret_val = write(fd,data,sizeof(data));
    if (ret_val < 0)
    {
        printf("LED Ctrl Failed\r\n");
        close(fd);
        return -1;
    }
    
    ret_val = close(fd);
    if (ret_val < 0)
    {
        printf("LED close failed\r\n");
        return -1;
    }
    
    return 0;
}